package com.zzh.bc.vo;

public class BaseRespVo<T> {
    public static final int RESULT_OK = 1;
    public static final int RESULT_ERROR = 0;

    private int code;
    private T data;
    private String msg;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg == null ? "" : msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static BaseRespVo respResultOK(Object data) {
        BaseRespVo vo = new BaseRespVo();
        vo.setCode(RESULT_OK);
        vo.setMsg("操作成功");
        vo.setData(data);
        return vo;
    }

    /**
     * 响应数据
     *
     * @param data 响应成功，描述
     * @return 返回封装好的bean
     */
    public static BaseRespVo respResultOK(String data) {
        BaseRespVo vo = new BaseRespVo();
        vo.setCode(RESULT_OK);
        vo.setMsg(data);
        return vo;
    }

    public static <T> BaseRespVo<T> respResultError() {
        BaseRespVo vo = new BaseRespVo();
        vo.setCode(RESULT_ERROR);
        vo.setMsg("操作失败");
        return vo;
    }

    public static <T> BaseRespVo<T> respResultError(String error) {
        BaseRespVo vo = new BaseRespVo();
        vo.setCode(RESULT_ERROR);
        vo.setMsg(error);
        return vo;
    }
}
